import axios from "axios";
//创建一个自己的axios实例，并且配置baseURL
let service = axios.create(
    {
        baseURL:'http://localhost:8088'
    }
)

//每一个请求之前拦截请求
service.interceptors.request.use(
    config =>{
        //如果token不为空
        if (localStorage.getItem('TOKEN') != null){
            //就自动在headers里添加token
            config.headers.TOKEN =localStorage.getItem('TOKEN');
        }
        //设置状态码在200-500之间都正常
        config.validateStatus = val => val >= 200&&val<=500;
        return config;
    }
)

export default service;